package cn.inps.platform.springbootdemostarter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author xxx
 * 自动配置类
 */
@Configuration   //标注为配置类 源码中可以看到 标注这个注解的类会被加载
@ConditionalOnClass(DemoService.class)
@EnableConfigurationProperties(DemoServiceProperties.class)   //开启配置文件
public class DemoAutoConfiguration {

    @Resource
    private DemoServiceProperties properties;     //注入配置文件

    @Bean
    @ConditionalOnMissingBean()     //该注解的意思是如果没有发现service的bean就执行新建一个bean
    public DemoService splicingService() {
        return new DemoService(properties.getPrefix(), properties.getSuffix());
    }

}
